package com.manage.handler;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class SqliteSinaHelper extends SQLiteOpenHelper {
	// 用来保存 USER_ID、Access Token、Access Secret的表名
	public static final String TB_NAME = "sinaUsers";

	public SqliteSinaHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	// 创建表
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE IF NOT EXISTS " + TB_NAME + "(" + SinaUser.ID + " integer primary key," + SinaUser.USER_ID
				+ " varchar," + SinaUser.TOKEN + " varchar," + SinaUser.TOKENSECRET + " varchar," + SinaUser.USER_NAME
				+ " varchar," + SinaUser.USER_ICON + " blob" + ")");
		// Log.e("Database", "onCreate");
	}

	// 更新表
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TB_NAME);
		onCreate(db);
		// Log.e("Database", "onUpgrade");
	}

	// 更新列
	public void updateColumn(SQLiteDatabase db, String oldColumn, String newColumn, String typeColumn) {
		try {
			db.execSQL("ALTER TABLE " + TB_NAME + " CHANGE " + oldColumn + " " + newColumn + " " + typeColumn);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
